package com.sword.controller.system;

import com.sword.pojo.system.Employee;
import com.sword.service.system.EmployeeService;
import com.sword.service.impl.system.EmployeeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class SystemController {
    @Autowired
    EmployeeService employeeService = new EmployeeServiceImpl();
    @RequestMapping("/system/user")
    public String user() {
        return "views/system/user";
    }

    @ResponseBody
    @RequestMapping("/system/getusers")
    public Map getusers() {
        List<Employee> employees = employeeService.queryAll();
        Map map = new HashMap();
        map.put("code", 0);
        map.put("data",employees);
        return map;
    }
    @ResponseBody
    @RequestMapping("/system/adduser")
    public Map adduser() {
        List<Employee> employees = employeeService.queryAll();
        Map map = new HashMap();
        map.put("code", 0);
        map.put("data",employees);
        return map;
    }
    @ResponseBody
    @RequestMapping("/system/deleteuser")
    public Map deleteuser(Integer id) {
        Integer result = employeeService.deleteEmployee(id);
        if (result == 1){
            Map map = new HashMap();
            map.put("success",true);
            map.put("message","删除成功");
            return map;
        }else {
            Map map = new HashMap();
            map.put("success",false);
            map.put("message","删除失败");
            return map;
        }
    }
}
